#ifndef _GSM0710_H_
#define _GSM0710_H_

/*
 * gsm0710.h -- definitions needed by the gsm0710 protocol daemon. 
 *
 * Copyright (C) 2003 Tuukka Karvonen <tkarvone@iki.fi>
 * 
 * Version 1.0 October 2003
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

// for debugging
//#ifdef DEBUG
//#  define PDEBUG(fmt, args...) DebugPrintf(DEBUG_LEVEL_ERR, fmt, ## args)
//#else
//#  define PDEBUG(fmt, args...) /* not debugging: nothing */
//#endif

// basic mode flag for frame start and end
#define GSM_F_FLAG 0xF9
//#define GSM_FLAG_STR "\x0F9"

// bits: Poll/final, Command/Response, Extension
#define GSM_PF 16
#define GSM_CR 2
#define GSM_EA 1
// the types of the frames
#define GSM_SABM 47
#define GSM_UA 99
#define GSM_DM 15
#define GSM_DISC 67
#define GSM_UIH 239
#define GSM_UI 3
// the types of the control channel commands
#define GSM_C_CLD 193
#define GSM_C_TEST 33
#define GSM_C_MSC 225
#define GSM_C_NSC 17
#define GSM_C_PSC 41
// V.24 signals: flow control, ready to communicate, ring indicator, data valid
// three last ones are not supported by Siemens TC_3x
#define GSM_S_FC 2
#define GSM_S_RTC 4
#define GSM_S_RTR 8
#define GSM_S_IC 64
#define GSM_S_DV 128

#define COMMAND_IS(command, type) ((type & ~GSM_CR) == command)
#define PF_ISSET(frame) ((frame->control & GSM_PF) == GSM_PF)
#define FRAME_IS(type, frame) ((frame->control & ~GSM_PF) == type)

// Channel status tells if the DLC is open and what were the last
// v.24 signals sent
typedef struct Channel_Status {
  char opened;
  unsigned char v24_signals;
} Channel_Status;

// for debugging 
//#define print_bits(n) printf("%d%d%d%d%d%d%d%d", ((n&128) == 128), \
//			     ((n&64) == 64),((n&32) == 32),((n&16) == 16), \
//			     ((n&8) == 8),((n&4) == 4),((n&2) == 2), \
//			     ((n&1) == 1));

int StartCMUX(void);
void ProcessCMUXData(unsigned short timeout);
void CloseCMUX(void);
void StopGSM(unsigned char channel);
void StartGSM(unsigned char channel);
int write_frame(int channel, const unsigned char *input, int count, unsigned char type);

#endif /* _GSM0710_H_ */
